package yannan.voiplock4ble.bean.ble;

import java.util.ArrayList;
import java.util.List;

import yannan.voiplock4ble.utils.ByteUtils;

/**
 * 说明：
 * 作者：mainTel
 * 时间：2016/12/5 13:36
 * 备注：
 */
public class PwdUser extends BaseBleResponse {
    /*
    5A A5 12 00 00 00 05 00 45 A0 01 01 0A 00 01 00 0B A1 D1 41 B3 CE
    //密码用户结构体


    //APP_GET_PW_LIST_ID

    //密码用户列表请求
    //由于信息内容长度为0，采用AppCommand_T
    //Example:5A A5 08 00 00 00 05 00 45 A0 4C E5

    //密码用户列表发送
    typedef struct {
        AppCommandHead_T head;
        uint8_t cmd;
        uint8_t reserve;	//对齐保留
        uint16_t token;
        uint8_t totalPwd;
        uint8_t packetUserNum;
        PwdUser_T  usrlist[];
    }UserPwdListSend_T;
        typedef struct{
        uint16_t userId;			//（每个密码用户ID为1Byte）传输时便于对齐采用2Byte定义
        BOOL pwdEnableFlag;		//是否被禁止开门（1:启用；0:未启用）
        uint32_t timeStamp;		//密码创建的时间戳
    }PwdUser_T;
    5A A5 1A 00 00 00 05 00 45 A0 //06 02 //0A 00 01 00 0B A1 D1 41// 0B 00 01 00 43 BB D1 41 5A 5B


    0A 00 01 00 0B A1 D1 41
    0B 00 01 00 43 BB D1 41

    无密码
     5A A5 0A 00 00 15 05 00 B7 8D 00 00 EB 40

     */

    public List<PwdUserItem> pwdUserItems;

    public int getTotalPwd() {
        return totalPwd;
    }

    public void setTotalPwd(int totalPwd) {
        this.totalPwd = totalPwd;
    }

    private int totalPwd;

    public PwdUser(byte[] response) {
        super(response);
        pwdUserItems = new ArrayList<>();
        totalPwd = content[0] & 0xff;
        if (totalPwd > 0)
            if ((content[1] & 0xff) == 0) {

            } else if ((content[1] & 0xff) == 1) {
                PwdUserItem item = new PwdUserItem();
                item.userId = content[2] & 0xff;
                item.pwdEnableFlag = content[4];
                item.timeStamp = Long.parseLong(ByteUtils.bytesToHexString(new byte[]{content[9], content[8], content[7], content[6]}), 16);
                pwdUserItems.add(item);
            } else if ((content[1] & 0xff) == 2) {
                PwdUserItem item = new PwdUserItem();
                item.userId = content[10] & 0xff;
                item.pwdEnableFlag = content[12];
                item.timeStamp = Long.parseLong(ByteUtils.bytesToHexString(new byte[]{content[17], content[16], content[15], content[14]}), 16);
                PwdUserItem item2 = new PwdUserItem();
                item2.userId = content[2] & 0xff;
                item2.pwdEnableFlag = content[4];
                item2.timeStamp = Long.parseLong(ByteUtils.bytesToHexString(new byte[]{content[9], content[8], content[7], content[6]}), 16);
                pwdUserItems.add(item);
                pwdUserItems.add(item2);
            }
    }

    public class PwdUserItem {
        public int userId;
        public int pwdEnableFlag;
        public long timeStamp;
    }
}
